package com.draw.b;

import java.util.Iterator;
import java.util.LinkedList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View.*;
import android.view.*;
import android.widget.Spinner;
import android.widget.Toast;

public class DrawView extends View implements OnTouchListener {
	public Context context;
	private LinkedList<ColorB> clrb;
	public ColorB red;
	public ColorB blue;
	public ColorB white;
	public ColorB black;
	private Paint paint=new Paint();
	private int hight;
	private int width;
	
	
	
	
	
	
	
	public DrawView(Context context ){
		
		super(context);
		this.context=context;
		red   = new ColorB(context, 5, 5);
		blue  = new ColorB(context ,5, 5);
		white = new ColorB(context ,5 ,5);
		black = new ColorB(context ,5 ,5);
		
		clrb = new LinkedList<ColorB>();
		
		setFocusableInTouchMode(true);
		this.setOnTouchListener(this);
		
		WindowManager windowmanger = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		Display display = windowmanger.getDefaultDisplay();
		
		
		this.hight=display.getHeight();
		this.width=display.getWidth();
		
		
		
		
	}
	

	public void onDraw(Canvas canvas){
		canvas.drawColor(0x000000);
		Iterator it = clrb.iterator();
		while(it.hasNext()){
			ColorB ball = (ColorB) it.next();
				
			System.out.println(ball.getColor());
			paint.setColor(ball.getColor());
			canvas.drawCircle(black.getBallx(), black.getBally(), 10, paint);
			ball.onMove(74,74,black);		
			
		}

		invalidate();
		
		
		
		
		
	}

	public void addBall(String c){
		ColorB ball = new ColorB(context , 2 , 2);
		ball.onMove(78,78,black);		
		clrb.add(ball);
		
		if(c.equals("red")){
			ball.setColor(Color.RED);
			ball.onMove(10,10,red);	
			
		}
		
		else if(c.equals("blue")){
			ball.setColor(Color.BLUE);
			ball.onMove(10,10,blue);	
		}
		
		else if(c.equals("white")){
			ball.setColor(Color.WHITE);
			ball.onMove(10,10,white);	
		}
		
		
	}

	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		black.setBallx((int)event.getX());
		black.setBally((int)event.getY());
		red.setBallx((int)event.getX());
		red.setBally((int)event.getY());
		blue.setBallx((int)event.getX());
		blue.setBally((int)event.getY());
		white.setBallx((int)event.getX());
		white.setBally((int)event.getY());
		invalidate();
		
		
		
		
		return false;
	}
	
	
	public void ballc(){
		clrb.add(new ColorB(context,width,hight));
	}
	

}
